@extends("admin.layouts.main")
<style>
    .card-body .form-group {
        width: 50%;
    }
    @media screen and (max-width: 1024px) {
        .card-body .form-group {
            width: 100% !important;
        }
    }
    .show-item {
        top: 40px;
        width: 100%;
        z-index: 10;
        background: white;
        overflow: hidden;
        display: none;
    }
    .showMsg {
        /* border:1px solid #ced4da ; */
    }
    .showMsg li {
        padding-bottom: 5px;
        cursor: pointer;
        padding: 10px 8px;
        margin: 2px 0;
    }
    .showMsg li:hover {
        background-color: #f2f2f2;
    }
    .w-50.text-right.mr-3 {
        width: 105% !important;
    }
    #pre_img {
        cursor: pointer;
    }
    #pre_img:hover {
        transform: scale(4);
    }
    .layui-btn.layui-btn-sm {
        vertical-align: top;
    }
</style>
<meta name="csrf-token" content="{{ csrf_token() }}">
@section("content")
<div class="container-fiuld p-3" id="app">
    <div class="card">
        <div class="card-body">
            <div class="pt-2 pb-2 d-flex justify-content-between align-items-center"
                 style="background-color:#f2f2f2;font-size:18px;">
                <h4 class="pl-2">推广内容设置</h4>
            </div>
            <form class="layui-form mt-3 ">
                <div class="form-group d-flex">
                    <label class="w-50 text-right mr-3" style="line-height:30px">推广URL:</label>
                    <input type="text" class="form-control" name="url" required lay-verify="required"
                           value="{{ isset($prom['url']) ? $prom['url'] : ''}}" placeholder="推广URL"/>
                </div>

                <div class="form-group d-flex layui-form-item">
                    <label class="layui-form-label w-50 mr-3 p-0">推广二维码:</label>
                    <div class="layui-input-block ml-0 text-left">
                        <img id="pre_img" style="height: 50px"/>
                        <button class="layui-btn layui-btn-sm " onclick="return false;" id="upload_img">
                            <i class="layui-icon">&#xe67c;</i>上传二维码
                        </button>
                        <input type="hidden" name="qcode_img" value="{{ isset($prom['qcode_img']) ? $prom['qcode_img'] : ''}}">
                    </div>
                </div>
				
                <div class="" style="margin-left:26rem">
                    <button class="layui-btn" lay-submit lay-filter="create-prom" data-url="{{ route('agsys.prom') }}"
                            data-type="POST">提交
                    </button>
                    <button type="reset" class="btn btn-danger">重置</button>
                </div>
            </form>
            <!-- <div class="alert alert-info mt-3 w-25">
              <strong>信息!</strong> 上传后不可自行修改，如需修改请联系专属客服
            </div> -->
        </div>
    </div>
</div>
@endsection
@section("js")
<script>
    //数据操作
    layui.use(['form', 'ori'], function () {
        var form = layui.form,
            ori = layui.ori,
            $ = layui.$;
		@if(!empty($prom['qcode_img'])) 
            $('#pre_img').attr('src', "{{$prom['qcode_img']}}");
		@endif
        form.on('submit(create-prom)', function (data) {
            ori.submit($(this), data.field, function () {
                window.location.reload();
            });
            return false;
        });
    });
    layui.use(['upload', 'jquery'], function () {
        $ = layui.jquery;
        $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}});
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_img', //绑定元素
            url: "/admin/kfupload", //上传接口
            accept: 'images',
			data: {type:'promimg'},
            done: function (res) {
                //上传完毕回调
                $('#pre_img').attr('src', res.msg);

                $('input[name="qcode_img"]').val(res.msg);
            }
            , error: function () {
                //请求异常回调
            }
        });
    });
</script>
@endsection
